package elka.gis.postman.bean;

import java.util.ArrayList;
import java.util.List;

/**
 * Wierzcholek
 * @author Wojtek
 *
 */
public class Vertex {
	private int id;
	private List<Edge> edges;

	public Vertex() {
		edges = new ArrayList<Edge>();
	}
	public Vertex (int id){
		this();
		this.id = id;
	}
	
	public Vertex(int id, List<Edge> edges){
		this.id = id;
		this.edges = edges;
	}
	public void addEdge(Edge edge) {
		edges.add(edge);
	}
	
	public List<Edge> getEdges() {
		return edges;
	}

	public void setEdges(List<Edge> edges) {
		this.edges = edges;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sprawdza czy wierzcholek ma nieparzysty stopien
	 * @return
	 */
	public boolean isOddDegree() {
		int degree = edges.size();
		return degree % 2 == 1 ? true : false;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Vertex other = (Vertex) obj;
		if(edges.size() != other.edges.size())
			return false;
		if (id != other.id)
			return false;
		return true;
	}
	
	public boolean equlas(Vertex v){
		return v.getId() == getId();
	}
	
	public Vertex copyWithoutEdges(){
		return new Vertex(getId());
	}
	
	public Vertex copyWithEdges(){
		return new Vertex(getId(), getEdges());
	}
	
}
